#include <iostream>
#include <string>
#include <cmath>

using namespace std;

bool pravil(int num) {
    if (num <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}


int main() {
    string input;
    getline(cin, input);
    string words[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int nums[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int n = 0;

    string num = "";
    for (int i = 0; i < input.length(); i++) {
        if (input[i] != ' ') {
            num += input[i];
        } else {
            }
            for (int j = 0; j < 10; j++) {
                if (num == words[j]) {
                    n = n * 10 + nums[j];
                    break;
                }
            if (j == 10){
                cout << "wrong input" << endl;
                return 0;
            }
            num = "";
        }
    }
    for (int j = 0; j < 10; j++) {
            if (num == words[j]) {
                n = n * 10 + nums[j];
                break;
            }
            if (j == 10){
                cout << "wrong input" << endl;
                return 0;
            }
    }

    if (n < 100 or 1000 <= n) {
        cout << "wrong input" << endl;
        return 0;
    }

    if (pravil(n)) {
        cout << n;
        return 0;
    }

    int pr = n;
    int pl = n;

    while (not pravil(pr)){
        pr++;
    }
    while (not pravil(pl)){
        pl--;
    }

    if ((pr - n) <= (n - pl)){
        cout << pr;
    }
    else{
        cout << pl;
    }
    return 0;
    }
